package com.xmtlxx.web.controller.oms.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import com.xmtlxx.common.annotation.Log;
import com.xmtlxx.common.annotation.RepeatSubmit;
import com.xmtlxx.common.core.controller.BaseController;
import com.xmtlxx.common.core.domain.PageQuery;
import com.xmtlxx.common.core.domain.R;
import com.xmtlxx.common.core.domain.entity.SysDictData;
import com.xmtlxx.common.core.page.TableDataInfo;
import com.xmtlxx.common.core.validate.AddGroup;
import com.xmtlxx.common.core.validate.EditGroup;
import com.xmtlxx.common.core.validate.QueryGroup;
import com.xmtlxx.common.enums.BusinessType;
import com.xmtlxx.common.utils.StringUtils;
import com.xmtlxx.common.utils.poi.ExcelUtil;
import com.xmtlxx.oms.domain.Task;
import com.xmtlxx.oms.domain.TaskVideoRecord;
import com.xmtlxx.oms.domain.bo.TaskBo;
import com.xmtlxx.oms.domain.bo.TaskDtlBo;
import com.xmtlxx.oms.domain.vo.DisposalApplyVo;
import com.xmtlxx.oms.domain.vo.TaskDtlExportVo;
import com.xmtlxx.oms.domain.vo.TaskDtlVo;
import com.xmtlxx.oms.domain.vo.TaskVo;
import com.xmtlxx.oms.service.ITaskDtlService;
import com.xmtlxx.oms.service.ITaskVideoRecordService;
import com.xmtlxx.system.service.ISysDictDataService;
import com.xmtlxx.web.controller.center.service.ICenterService;
import com.xmtlxx.web.controller.center.service.ICommonService;
import com.xmtlxx.web.controller.center.vo.SendTaskVo;
import com.xmtlxx.web.controller.oms.service.ITaskService;
import com.xmtlxx.web.controller.wms.service.IExWarehouseService;
import com.xmtlxx.wms.domain.ExWarehouse;
import com.xmtlxx.wms.domain.bo.ExWarehouseBo;
import com.xmtlxx.wms.domain.vo.DataVo;
import com.xmtlxx.wms.domain.vo.ExWarehouseDtlVo;
import com.xmtlxx.wms.domain.vo.ExWarehouseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 出入库订单Controller
 *
 * @author xmtlxx
 * @date 2022-08-12
 */
@Validated
@Api(value = "出入库订单控制器", tags = {"出入库订单管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/oms/task")
public class TaskController extends BaseController {

    private final ITaskService iTaskService;

    private final ISysDictDataService iSysDictDataService;

    private final ICommonService commonService;

    private final ICenterService centerService;

    private final ITaskDtlService iTaskDtlService;

    private final IExWarehouseService iExWarehouseService;

    private final ITaskVideoRecordService taskVideoRecordService;

    /**
     * 返回一个初始化的对象到前端，方便进行动态渲染
     */
    @ApiOperation("用于返回一个初始化对象")
    @PostMapping("/initBean")
    public R<TaskVo> initBean(@Validated(AddGroup.class) @RequestBody TaskVo taskVo) {

        return R.ok(iTaskService.initBean(taskVo));
    }

    /**
     * 返回一个初始化的对象到前端，方便进行动态渲染
     */
    @ApiOperation("用于返回一个初始化对象")
    @PostMapping("/initReturnBean")
    public R<TaskVo> initReturnBean(@Validated(AddGroup.class) @RequestBody TaskVo taskVo) {

        return R.ok(iTaskService.initReturnBean(taskVo));
    }


    /**
     * 返回一个初始化的对象到前端，方便进行动态渲染
     */
    @ApiOperation("用于返回一个初始化对象")
    @PostMapping("/initDealBean")
    public R<TaskVo> initDealBean(@Validated(AddGroup.class) @RequestBody TaskVo taskVo) {

        return R.ok(iTaskService.initDealBean(taskVo.getIds()));
    }

    /**
     * 查询出入库订单列表
     */
    @ApiOperation("查询出入库订单列表")
    @SaCheckPermission("oms:task:list")
    @GetMapping("/list")
    public TableDataInfo<TaskVo> list(@Validated(QueryGroup.class) TaskBo bo, PageQuery pageQuery) {
        return iTaskService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出出入库订单列表
     */
    @ApiOperation("导出出入库订单列表")
    @SaCheckPermission("oms:task:export")
    @Log(title = "出入库订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated TaskBo bo, HttpServletResponse response) {

        List<TaskVo> list = iTaskService.queryList(bo);
        ExcelUtil.exportExcel(list, "出入库订单", TaskVo.class, response);
    }

    /**
     * 获取出入库订单详细信息
     */
    @ApiOperation("获取出入库订单详细信息")
//    @SaCheckPermission("oms:task:query")
    @GetMapping("/{id}")
    public R<TaskVo> getInfo(@ApiParam("主键")
                             @NotNull(message = "主键不能为空")
                             @PathVariable("id") String id) {

        return R.ok(iTaskService.getTaskById(id));
    }

    /**
     * 新增出入库订单
     */
    @ApiOperation("新增出入库订单")
    @SaCheckPermission("oms:task:add")
    @Log(title = "出入库订单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Transactional(rollbackFor = Exception.class)
    public R<TaskVo> add(@Validated(AddGroup.class) @RequestBody TaskVo vo) {

        TaskBo bo = new TaskBo();
        BeanUtil.copyProperties(vo, bo);
        TaskVo taskVo = null;
        for (TaskDtlVo item : vo.getItems()) {
            if(item.getPno().startsWith("Z")){
                bo.setXzType("1");
                break;
            }
        }
        if (vo.getType().equals("3") && StringUtils.isNotEmpty(vo.getAddType()) && vo.getAddType().equals("return")) {//调用归还入库
            taskVo = iTaskService.insertReturnTaskBo(bo);

            //调用归还申请为自行配送时，自动下发
            if (taskVo != null && taskVo.getDelivery().equals("1")) {
                SendTaskVo sendTaskVo = new SendTaskVo();
                sendTaskVo.setStoreId(taskVo.getStoreId());
                sendTaskVo.setCarrierDeptId(0l);
                String[] ids = new String[]{taskVo.getId()};
                sendTaskVo.setIds(ids);
                centerService.sendsTask(sendTaskVo);
            }

        } else {
            if (StringUtils.isEmpty(bo.getStoreId()) && StringUtils.isNotEmpty(bo.getIsDevolve()) && bo.getIsDevolve().equals("1")) {//移交上级库，不进行下发
                taskVo = iTaskService.insertTransferTaskBo(bo);
                return R.ok(taskVo);
            }
            taskVo = iTaskService.insertTaskBo(bo);
            //入库申请为自行配送时，自动下发
            if (taskVo != null && taskVo.getDelivery().equals("1")) {
                SendTaskVo sendTaskVo = new SendTaskVo();
                sendTaskVo.setStoreId(taskVo.getStoreId());
                sendTaskVo.setCarrierDeptId(0l);
                String[] ids = new String[]{taskVo.getId()};
                sendTaskVo.setIds(ids);
                switch (taskVo.getType()) {
                    case "0":
                        centerService.sendsTask(sendTaskVo);
                        break;
                    case "2":
                        break;
                    default:
                        if (taskVo.getCheckStatus().equals("1")) {
                            centerService.sendsTask(sendTaskVo);
                        }
                        break;
                }
            }
        }
        return R.ok(taskVo);
    }

    /**
     * 入库视频保存
     */
    @ApiOperation("入库视频保存")
    @Log(title = "出入库订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/uploadVideo")
    @Transactional(rollbackFor = Exception.class)
    public R<TaskVo> uploadVideo(@Validated(AddGroup.class) @RequestBody TaskVo vo) {

        vo = iTaskService.uploadVideo(vo);
        return R.ok(vo);
    }

    /**
     * 修改出入库订单
     */
    @ApiOperation("修改出入库订单")
    @SaCheckPermission("oms:task:edit")
    @Log(title = "出入库订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Transactional(rollbackFor = Exception.class)
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TaskVo vo) {

        TaskBo bo = new TaskBo();
        TaskVo oldVo = iTaskService.getTaskById(vo.getId());
        String delivery = oldVo.getDelivery();//原配送方式 当原配送方式为自行配送，修改后 撤回下发 重置为待下发
        BeanUtil.copyProperties(vo, bo);
        Integer flag = iTaskService.updateTaskBo(bo) != null ? 1 : 0;

        if (flag == 1) {
            TaskBo updatebo = new TaskBo();
            TaskVo task = iTaskService.queryById(bo.getId());
            BeanUtil.copyProperties(task, updatebo);
            switch (task.getType()) {
                case "0":
                    //上门取件修改为自行配送
                    if (task.getDelivery().equals("1")) {
                        SendTaskVo sendTaskVo = new SendTaskVo();
                        sendTaskVo.setStoreId(task.getStoreId());
                        sendTaskVo.setCarrierDeptId(0l);
                        String[] ids = new String[]{task.getId()};
                        sendTaskVo.setIds(ids);
                        centerService.sendsTask(sendTaskVo);

                        //更新下发状态
                        updatebo.setSendStatus("1");
                        updatebo.setSendReStatus("1");
                        iTaskService.updateTaskEnty(updatebo);
                    }
                    break;
                default:
                    //已审核，并且是自行配送
                    if (task.getCheckStatus().equals("1") && task.getDelivery().equals("1")) {
                        SendTaskVo sendTaskVo = new SendTaskVo();
                        sendTaskVo.setStoreId(task.getStoreId());
                        sendTaskVo.setCarrierDeptId(0l);
                        String[] ids = new String[]{task.getId()};
                        sendTaskVo.setIds(ids);
                        centerService.sendsTask(sendTaskVo);

                        //更新下发状态
                        updatebo.setSendStatus("1");
                        updatebo.setSendReStatus("1");
                        iTaskService.updateTaskEnty(updatebo);
                    }
                    break;
            }
            //原配送方式 当原配送方式为自行配送，修改为上门取件后 撤回下发 重置为待下发
            if (delivery.equals("1") && task.getDelivery().equals("0")) {
                centerService.cancelSendTask(task);
                //更新下发状态
                updatebo.setSendStatus("0");
                updatebo.setSendReStatus("0");
                iTaskService.updateTaskEnty(updatebo);
            }
        }
        return toAjax(flag);
    }

    /**
     * 订单审核
     */
    @ApiOperation("订单审核")
    @SaCheckPermission("oms:task:edit")
    @Log(title = "出入库订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/check")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> checkTask(@Validated(EditGroup.class) @RequestBody TaskVo taskVo) {

        Task task = iTaskService.checkTask(taskVo);
        Integer flag = 0;

        if (task != null) {
            TaskBo updatebo = new TaskBo();
            BeanUtil.copyProperties(task, updatebo);
            //已审核，并且是自行配送
            if (taskVo.getCheckStatus().equals("1") && task.getType().equals("2")) {
//                if(task.getSource().equals("1")){
//                    centerService.sendDealTask(task);
//                }
                TaskDtlBo dtlBo = new TaskDtlBo();
                dtlBo.setTaskId(taskVo.getId());
                List<TaskDtlVo> dtls = iTaskDtlService.queryList(dtlBo);
                ExWarehouseBo exWarehouseBo = new ExWarehouseBo();
                exWarehouseBo.setTaskId(taskVo.getId());
                List<ExWarehouseVo> exWarehouseVos = iExWarehouseService.queryList(exWarehouseBo);
                if (exWarehouseVos == null || exWarehouseVos.size() == 0) {
                    exWarehouseBo.setDeptId(taskVo.getDeptId());
                    exWarehouseBo.setStoreId(taskVo.getStoreId());
                    exWarehouseBo.setType(taskVo.getPropertyType());
                    exWarehouseBo.setReason(taskVo.getRemark());
                    exWarehouseBo.setTargetId(taskVo.getDeptId());
                    exWarehouseBo.setContacts(taskVo.getName());
                    exWarehouseBo.setTel(taskVo.getTel());
                    exWarehouseBo.setAddress(taskVo.getAddress());
                    exWarehouseBo.setLng(taskVo.getLng());
                    exWarehouseBo.setLat(taskVo.getLat());
                    exWarehouseBo.setFlag(taskVo.getDelivery());
                    exWarehouseBo.setNums(taskVo.getNums());

                    List<ExWarehouseDtlVo> exDtls = new ArrayList<>();
                    if (dtls != null && dtls.size() > 0) {
                        for (TaskDtlVo dtl : dtls) {
                            ExWarehouseDtlVo exwdtl = new ExWarehouseDtlVo();
                            exwdtl.setPno(dtl.getPno());
                            exwdtl.setName(dtl.getName());
                            exwdtl.setDeptId(dtl.getDeptId());
                            exwdtl.setOrgId(dtl.getLocalId());
                            exwdtl.setNums(dtl.getNums());
                            exwdtl.setDelFlag("0");
                            exwdtl.setStatus("0");
                            exDtls.add(exwdtl);
                        }
                    }
                    exWarehouseBo.setItems(exDtls);
                    ExWarehouse exWarehouse = iExWarehouseService.insertByBo(exWarehouseBo);
                }
            } else if (task.getCheckStatus().equals("1") && task.getDelivery().equals("1")) {
                SendTaskVo sendTaskVo = new SendTaskVo();
                sendTaskVo.setStoreId(task.getStoreId());
                sendTaskVo.setCarrierDeptId(0l);
                String[] ids = new String[]{task.getId()};
                sendTaskVo.setIds(ids);
                centerService.sendsTask(sendTaskVo);

                //更新下发状态
                updatebo.setSendStatus("1");
                updatebo.setSendReStatus("1");
                iTaskService.updateTaskEnty(updatebo);
            }

            flag = 1;
        }
        return toAjax(flag);
    }

    /**
     * 修改出入库订单
     */
    @ApiOperation("修改出入库订单")
    @SaCheckPermission("oms:task:edit")
    @PostMapping("/updateTask")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> updateTask(@Validated(EditGroup.class) @RequestBody TaskVo taskVo) {

        TaskBo bo = new TaskBo();
        BeanUtil.copyProperties(taskVo, bo);
        return toAjax(iTaskService.updateTaskEnty(bo));
    }

    /**
     * 更新归还时间
     */
    @ApiOperation("更新归还时间")
    @SaCheckPermission("oms:task:edit")
    @PostMapping("/updateReturnTime")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> updateReturnTime(@Validated(EditGroup.class) @RequestBody TaskVo taskVo) {

        TaskBo bo = new TaskBo();
        BeanUtil.copyProperties(taskVo, bo);
        return toAjax(iTaskService.returnTimeUpdate(bo));
    }

    /**
     * 返回一个初始化的对象到前端，方便进行动态渲染
     */
    @ApiOperation("用于返回一个初始化对象")
    @PostMapping("/initReplaceBean")
    public R<TaskVo> initReplaceBean(@Validated(AddGroup.class) @RequestBody TaskVo taskVo) {

        return R.ok(iTaskService.initReplaceBean(taskVo));
    }

    /**
     * 修改出入库订单
     */
    @ApiOperation("转处置单")
    @SaCheckPermission("oms:task:edit")
    @PostMapping("/replaceTask")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> replaceTask(@Validated(EditGroup.class) @RequestBody TaskVo taskVo) {

        TaskBo bo = new TaskBo();
        BeanUtil.copyProperties(taskVo, bo);
        return toAjax(iTaskService.replaceTask(bo));
    }


    /**
     * 处置确认
     */
    @ApiOperation("处置清单原件上传")
    @SaCheckPermission("oms:task:edit")
    @Log(title = "处置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/dealUpload")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> dealUpload(@Validated(AddGroup.class) @RequestBody TaskVo taskVo) {

        TaskBo bo = new TaskBo();
        BeanUtil.copyProperties(taskVo, bo);
        return toAjax(iTaskService.updateTaskEnty(bo));

    }

    /**
     * 删除出入库订单
     */
    @ApiOperation("删除出入库订单")
    @SaCheckPermission("oms:task:remove")
    @Log(title = "出入库订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> remove(@ApiParam("主键串")
                          @NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {

        return toAjax(iTaskService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 删除订单明细
     */
    @ApiOperation("删除订单明细")
    @PostMapping("/removeDtl")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> removeDtl(@Validated(EditGroup.class) @RequestBody TaskVo taskVo) {

        TaskBo bo = new TaskBo();
        BeanUtil.copyProperties(taskVo, bo);
        return toAjax(iTaskService.deleteWithDtlByIds(bo));
    }

    /**
     * 删除订单明细
     */
    @ApiOperation("撤销订单")
    @Log(title = "撤销订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeTask/{id}")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> removeTask(@ApiParam("主键串")
                              @NotEmpty(message = "主键不能为空")
                              @PathVariable String id, String cancelReason) {

        boolean flag = iTaskService.deleteWithTask(id, cancelReason);
        if (flag) {
            commonService.taskPush(id, "1");
        }
        return toAjax(flag);
    }

    /**
     * 删除订单明细
     */
    @ApiOperation("撤销订单")
    @Log(title = "撤销订单", businessType = BusinessType.DELETE)
    @SaCheckPermission("oms:task:removeByAdmin")
    @DeleteMapping("/removeTaskByAdmin/{id}")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> removeTaskByAdmin(@ApiParam("主键串")
                                     @NotEmpty(message = "主键不能为空")
                                     @PathVariable String id, String cancelReason) {

        boolean flag = iTaskService.deleteWithTaskByAdmin(id, cancelReason);
        if (flag) {
            commonService.taskPush(id, "1");
        }
        return toAjax(flag);
    }

    /**
     * 恢复订单及下发文件
     */
    @ApiOperation("恢复订单")
    @GetMapping("/restoreTask/{id}")
    @Log(title = "恢复订单", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class)
    public R<Void> restoreTask(@ApiParam("主键串")
                               @NotEmpty(message = "主键不能为空")
                               @PathVariable String id) {

        boolean flag = iTaskService.restoreWithTask(id);
        if (flag) {
            commonService.taskPush(id, "0");
        }
        return toAjax(flag);
    }

    /**
     * 统计区县数据
     */
    @ApiOperation("统计区县数据")
    @GetMapping("/statisticsTask")
    public R<Map<String, Object>> statisticsTask(@Validated(QueryGroup.class) TaskBo bo) {

        Map<String, Object> data = new HashMap<>();
        List<TaskVo> taskVos = iTaskService.outTaskStatistics(bo);

        SysDictData dictData = new SysDictData();
        dictData.setDictType("wms_put_task_area");
        List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(dictData);

        //taskVo转dataVo
        List<DataVo> taskData = taskVos.stream().map(item -> {
            DataVo dataVo = new DataVo();
            dataVo.setRegion(item.getDictValue());
            dataVo.setRegionName(item.getDictLabel());
            dataVo.setTotals(item.getTotals());
            return dataVo;
        }).collect(Collectors.toList());


        List<DataVo> dictDataVos = dictDataList.stream().map(item -> {
            DataVo dataVo = new DataVo();
            dataVo.setRegion(item.getDictValue());
            dataVo.setRegionName(item.getDictLabel());
            dataVo.setTotals(0l);
            return dataVo;
        }).collect(Collectors.toList());

        //taskData 合并到 dictDataVos
        List<DataVo> result = dictDataVos.stream().map(d -> {
            taskData.stream().filter(d2 -> Objects.equals(d.getRegion(), d2.getRegion())).forEach(d2 -> {
                BeanUtil.copyProperties(d2, d);
            });
            return d;
        }).collect(Collectors.toList());
        result = result.stream().filter(item -> !item.getRegion().equals("QB")).collect(Collectors.toList());
        data.put("result", result);

        return R.ok(data);
    }

    /**
     * 导出出入库订单明细列表
     */
    @ApiOperation("导出订单列表")
    @Log(title = "出入库订单", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTaskDtl")
    public void exportTaskDtl(@Validated TaskBo bo, HttpServletResponse response) {

        List<TaskDtlExportVo> list = iTaskDtlService.queryExportList(bo);
        Integer index = 1;
        List<TaskDtlExportVo> result = new ArrayList<>();
        if (list != null && list.size() > 0) {
            for (TaskDtlExportVo item : list) {
                boolean had = false;
                //
                if (result != null && result.size() > 0) {
                    for (TaskDtlExportVo dtl : result) {
                        if (dtl.getPno().equals(item.getPno())) {
                            dtl.setTaskNo(dtl.getTaskNo() + "," + item.getTaskNo());
                            had = true;
                        }
                    }
                }
                if (!had) {
                    item.setIndex(index);
                    String status = "";
                    if (item.getInums() != null) {
                        status += "在库(" + item.getInums() + ") ";
                    }
                    if (item.getTnums() != null && item.getTnums() != 0) {
                        status += "调用(" + item.getTnums() + ") ";
                    }
                    if (item.getRnums() != null && item.getRnums() != 0) {
                        status += "归还(" + item.getRnums() + ") ";
                    }
                    if (item.getDeals() != null && item.getDeals() != 0) {
                        status += "处置(" + item.getDeals() + ") ";
                    }
                    if (item.getOutnums() != null && item.getOutnums() != 0) {
                        status += "出库(" + item.getOutnums() + ") ";
                    }
                    if (item.getEoutnums() != null && item.getEoutnums() != 0) {
                        status += "出库取证(" + item.getEoutnums() + ") ";
                    }
                    if (item.getEtnums() != null && item.getEtnums() != 0) {
                        status += "调用取证(" + item.getEtnums() + ") ";
                    }
                    item.setStatus(status);

                    String locator = "";
                    locator += !StringUtils.isEmpty(item.getStoreName()) ? item.getStoreName() + "/" : "";
                    locator += !StringUtils.isEmpty(item.getAreaName()) ? item.getAreaName() + "/" : "";
                    locator += !StringUtils.isEmpty(item.getGroupName()) ? item.getGroupName() + "/" : "";
                    locator += !StringUtils.isEmpty(item.getCabinetName()) ? item.getCabinetName() + "/" : "";
//                locator += !StringUtils.isEmpty(item.getFloors())?item.getFloors()+"/":"";
                    locator += !StringUtils.isEmpty(item.getLocatorName()) ? item.getLocatorName() : "";
                    item.setLocalName(locator);
                    result.add(item);
                    index++;
                }
            }
        }
        // 从第几行开始合并
//        int mergeStartRowIndex = 1;
        // 需要合并哪些列
//        int[] mergeColumns = {1,2};
        ExcelUtil.exportExcel(result, "订单明细", TaskDtlExportVo.class, response);
    }

    /**
     * 恢复订单及下发文件
     */
    @ApiOperation("重新上传交接原件")
    @PostMapping("/reviewOss")
    @Log(title = "重新上传交接原件", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class)
    public R<Void> reviewOss(@Validated(AddGroup.class) @RequestBody TaskVo taskVo) {

        return toAjax(iTaskService.reviewOss(taskVo.getId(), taskVo.getOss()));
    }


    @ApiOperation("获取订单视频记录")
    @GetMapping("/videoRecord")
    public R<List<TaskVideoRecord>> getVideoRecord(@ApiParam("任务id") @NotEmpty(message = "任务id不能为空") String taskId) {

        return R.ok(taskVideoRecordService.getTaskVideoRecord(taskId));
    }

    @ApiOperation("插入订单视频记录")
    @PostMapping("/videoRecord")
    public R<Void> insertVideoRecord(@RequestBody TaskVideoRecord taskVideoRecord) {

        return toAjax(taskVideoRecordService.insert(taskVideoRecord));
    }

    @ApiOperation("删除订单视频记录")
    @Log(title = "订单视频记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/videoRecord/{id}")
    public R<Void> removeVideoRecord(@ApiParam("主键串") @NotEmpty(message = "主键不能为空") @PathVariable String id) {

        return toAjax(taskVideoRecordService.deleteTaskVideoRecord(id));
    }


    @ApiOperation("导出处置申请")
    @SaCheckPermission("oms:task:export")
    @Log(title = "处置申请", businessType = BusinessType.EXPORT)
    @PostMapping("/disposal/apply/export")
    public void disposalApplyExport(@Validated TaskBo bo, HttpServletResponse response) {
        List<DisposalApplyVo> disposalApplyList = iTaskService.getDisposalApplyList(bo);
        ExcelUtil.exportExcel(disposalApplyList, "处置申请", DisposalApplyVo.class, response);
    }
}
